/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engine.ani;

import java.util.Hashtable;
import javax.microedition.lcdui.Graphics;
import mainpackage.Constant;
import mainpackage.MainLogic;
import mainpackage.MainView;
import mainpackage.ResManager;
import mainpackage.Tools;

/**
 *
 * @author Administrator
 */
public class OtherPlayer {
    //Other id

    public long[] shOtherIds;
    //名字
    public String[] strOtherNames;
    public String[] strOtherTongNames;
    private String[] mark = {"[", "]"};
    //等级
//    public short[] shOtherLeves;
    //速度
    public short[] shOtherSpeed;
    //位置 当前 xy 目标 xy
    public int[] iOtherXs, iOtherYs, iObjXs, ObjYs;
    //过去位置
    //玩家职业+ 性别标识区别动画文件0-2 男 3-5 女
    public byte[] byOtherJobs;
      public byte[] byOtherSex;
    //当前hp
    public short[] shOtherHps;
    //maxHp
    public short[] shOtherMaxHps;
    //当前mp
    public short[] shOtherMps;
    //maxMp
    public short[] shOtherMaxMps;
    //状态
    public byte[] byOtherState;
    public byte[] byupdateOtherState;
    //方向
    public byte[] byOtherDirection;
    //图片资源
    public short shOtherIndex;
    //资源初始化完毕
    public boolean blOtherResInitOver;
    //根据时间计算的移动步长
    private int iStep;
    //Other容器
    public Hashtable repeatTable;
    //Other图片容器
//    private Image imgShadow;
    //服务器时间
    //任务frame间隔时间
    private long[] lUpdateTime;
    //当前时间
    private long[] lCurrentTime;
    //和服务器时间差
    //本地走路开始时间
    private long[] lStartTime;
    //走路持续时间
    private int[] iMoveDistance;
    private int[] iContinueTime;
    private int[] iPkPoint;
    private int[] iNameColor;
    public int[][] iNpcAniPre;
    //资源id
    public int[] strOtherResIds;
    //avatar鞋子
    public short[] aniAvatarShoes = null;
    //avatar衣服
    public short[] aniAvatarCloes = null;
    //avatar头发
    public short[] aniAvatarHear = null;
    public short[] aniAvatarHead = null;
    //avatar裤子
    public short[] aniAvatarTrousers = null;
    //weapon武器
    public short[] aniAvatarWeapon = null;
    public int[][] ianiAvatarShoesPre;
    public int[][] ianiAvatarCloesPre;
    public int[][] ianiAvatarTrousersPre;
    public int[][] ianiAvatarHear;
    public int[][] ianiAvatarHead;
    public int[][] ianiAvatarWeaponPre;
    public int[][] ianiPetPre;
    //动画数组
    private int[] iTongColor;//帮派颜色

    public OtherPlayer() {
        this.initOther();
    }

    //初始化Other基本数据
    public void initOther() {
        this.shOtherIds = new long[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byOtherJobs = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        byOtherSex = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.strOtherNames = new String[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.strOtherTongNames = new String[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.strOtherResIds = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iOtherXs = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iOtherYs = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iObjXs = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.ObjYs = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.shOtherHps = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.shOtherMaxHps = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.shOtherMps = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.shOtherMaxMps = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byOtherState = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byupdateOtherState = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byOtherDirection = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.repeatTable = new Hashtable();
        this.shOtherSpeed = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.lUpdateTime = new long[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        //当前时间
        this.lCurrentTime = new long[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        //和服务器时间差
        //本地走路开始时间
        this.lStartTime = new long[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        //走路持续时间
        this.iContinueTime = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iMoveDistance = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPkPoint = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iNameColor = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        iTongColor = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iNpcAniPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        this.ianiAvatarShoesPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        this.ianiAvatarCloesPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        this.ianiAvatarTrousersPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        ianiAvatarHear = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        ianiAvatarHead  = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        this.ianiAvatarWeaponPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        this.ianiPetPre = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN][5];
        /*******宠物***********************/
        bStartMoveToDest = new boolean[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.bStandNextTime = new boolean[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.lStopStartTime = new long[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        iPetStopTime = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byPetDirection = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPetX = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPetY = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPetDestX = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPetDestY = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byPetStatus = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.byPetSpeed = new byte[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.iPetAniID = new int[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.sPetNick = new String[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.shPetHeight = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.aniAvatarShoes = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.aniAvatarCloes = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.aniAvatarShoes = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.aniAvatarTrousers = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        aniAvatarHead = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        aniAvatarHear = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        this.aniAvatarWeapon = new short[Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN];
        for (int i = Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN - 1; i >= 0; i--) {
            this.shOtherIds[i] = -1;
            this.byOtherJobs[i] = -1;
            byOtherSex[i] = -1;
            this.strOtherNames[i] = null;
            this.strOtherTongNames[i] = null;
//            this.shOtherLeves[i] = -1;
            this.strOtherResIds[i] = -1;
            this.iOtherXs[i] = -1;
            this.iOtherYs[i] = -1;
            this.iObjXs[i] = -1;
            this.ObjYs[i] = -1;
            this.byOtherState[i] = -1;
            this.byupdateOtherState[i] = -1;
            this.byOtherDirection[i] = -1;
            this.shOtherSpeed[i] = -1;
            //当前时间
            this.lCurrentTime[i] = -1;
            //和服务器时间差
            //本地走路开始时间
            this.lStartTime[i] = -1;
            //走路持续时间
            this.iContinueTime[i] = -1;
            this.iMoveDistance[i] = -1;
            this.lUpdateTime[i] = -1;
            this.iPkPoint[i] = 0;
            this.iNameColor[i] = 0xffffff;
            iTongColor[i] = 0xffffff;
//            this.shPlayerOnePelsSpeedTime[i] = -1;
            //this.aniAvatarPet[i] = MainLogic.getInstance().aResManager.getAvatar(avatarId);
            bStartMoveToDest[i] = false;
            this.bStandNextTime[i] = false;
            lStopStartTime[i] = System.currentTimeMillis();
            iPetStopTime[i] = Tools.random(3000, 10000);
            this.byPetDirection[i] = this.byOtherDirection[i];
            this.iPetX[i] = this.iOtherXs[i] + iPetMaxOffset;
            this.iPetY[i] = this.iOtherYs[i];
            this.byPetStatus[i] = 0;
            this.byPetSpeed[i] = 2;
            this.iPetAniID[i] = -1;
            this.sPetNick[i] = null;
            this.shPetHeight[i] = 0;
            this.iPetDestX[i] = 0;
            this.iPetDestY[i] = 0;

        }
        try {
//            this.imgShadow = ResManager.createImage(90000072, Constant.RES_PUBLIC_TEMP, Constant.RES_UI_PATH, false, -1);
//            this.imgShadow = Tools.makeTransparent(this.imgShadow, 70);
            //ResManager.clearRes(90000072, Constant.RES_PUBLIC_TEMP, Constant.RES_TYPE_IMAGE);
        } catch (Exception ex) {
            if (Constant.DEBUG) {
                ex.printStackTrace();
            }
        }
    }

    public void changecolor(int index, int pkpoint) {
        if (index == -1 || pkpoint == -1) {
            return;
        }
          //#if NOKIA_S40V3 || MOTO || K790|| NOKIA_S60V5 || NORMAL_240_400
         this.iNameColor[index] = 0xffcc00;
                  //#else
//#         this.iNameColor[index] = 0xffffff;
                  //#endif
        
        if (pkpoint > 0 && pkpoint < 30) {
            this.iNameColor[index] = 0xffcc00;
        } else if (pkpoint >= 30) {
            this.iNameColor[index] = 0xff3333;
        }
    }

    public void changeTongColor(int index, byte duty) {
        if (index == -1 || duty == -1) {
            return;
        }
        switch (duty) {
            case 0://帮众
                 //#if NOKIA_S40V3 || NOKIA_S60V5 || NORMAL_240_400
                 iTongColor[index] = 0x00ffff;
                //#else
//#                  iTongColor[index] = 0xffffff;
                //#endif
                break;
            case 1://长老
                iTongColor[index] = 0x00ffff;
                break;
            case 2://护法
                iTongColor[index] = 0x0099ff;
                break;
            case 3://副帮主
                iTongColor[index] = 0xffff00;
                break;
            case 4://帮主
                iTongColor[index] = 0xffcc00;
                break;
        }
    }

    public int getOther(long id) {
           if(id != -1)
           {
               if(this.repeatTable.containsKey(new Long(id)))
            return  ((Integer) (this.repeatTable.get(new Long(id)))).intValue();
         }
        return -1;
//        for (int i = this.shOtherIds.length - 1; i >= 0; i--) {
//            if (this.shOtherIds[i] == id) {
//                return i;
//            }
//        }
//        return -1;
    }

    public void addAvatarAni(int index, String avatarId, byte position) {

//#if NOKIAN73 || NOKIA_S40V3 || MOTO || K790|| NORMAL_240_400
//#         return;
//#else
        try {
            if (index == -1 || avatarId.equals("0")) {
                return;
            }
            int indexa = avatarId.indexOf(",");
            short avatarIda = -1;
            if (indexa != -1) {
                avatarIda = (short) ((getPlayerSex(this.strOtherResIds[index]) == Constant.PLAYER_SEX_MAN) ? Integer.parseInt(avatarId.substring(0, indexa)) : Integer.parseInt(avatarId.substring(indexa + 1)));
            } else {
                avatarIda = (short) (Integer.parseInt(avatarId));
            }
//            Tools.printLog("其他玩家添加装备：" + "index" + index + "strOtherNames" + strOtherNames[index] + "avatarId" + avatarId + "position" + position);
            ResManager.loadAnimation(avatarIda, Constant.RES_PUBLIC_ONEROOM, true);
            switch (position) {
                case Constant.PLAYER_AVATAR_SHOES:
                    aniAvatarShoes[index] = avatarIda;
                    break;
                case Constant.PLAYER_AVATAR_CLOTH:
                    aniAvatarCloes[index] = avatarIda;
                    break;
                case Constant.PLAYER_AVATAR_TROUSERS:
                    aniAvatarTrousers[index] = avatarIda;
                    break;
                case Constant.PLAYER_AVATAR_WEAPON:
                    aniAvatarWeapon[index] = avatarIda;
                    break;
                 case  Constant.PLAYER_AVATAR_HEAR:
                    this.aniAvatarHear[index] = avatarIda;
                    break;
                    case  Constant.PLAYER_AVATAR_HEAD:
                    this.aniAvatarHead[index]= avatarIda;
                        break;
            }
            this.changeAction(index, (byte) 0, byOtherState[index], byOtherDirection[index]);
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
//#endif

    }

    public void show(Graphics g, int x, int y, int index) {
//        show(g, iOtherX[index] - x, iOtherY[index] - y, this.blMirror, this.blApeak);
    }

    public void show(Graphics g, int x, int y, boolean mirror, boolean apeak) {
//        //绘制Other动画
//        super.show(g, x, y, mirror, apeak);
//        this.nextFrame(true);
//        //绘制其他
    }

    public void addOther(long OtherId, byte job,byte sex, String aniid, String imgId, String AniId, String OtherName, short Otherlv, short hp,
            short maxHp, short mp, short maxMp, byte state, byte action, byte direct, int x, int y, short speed, int pkpoint, String tongname, byte duty) {
        try {
            byte directa = 0;
            if (direct == Constant.PLAYER_DIRECTION_DOWN) {
                directa = Constant.PLAYER_DIRECTION_UP;
            } else if (direct == Constant.PLAYER_DIRECTION_UP) {
                directa = Constant.PLAYER_DIRECTION_DOWN;
            } else {
                directa = direct;
            }
                     int index = aniid.indexOf(",");
            int avatarId = -1;
            if (index != -1) {
                avatarId = (sex == Constant.PLAYER_OCCUPTION_ASSASSIN) ? Integer.parseInt(aniid.substring(0, index)) : Integer.parseInt(aniid.substring(index + 1));
            } else {
                avatarId = Integer.parseInt(aniid);
            }  
//            Tools.printLog("add playername" + OtherName + "playerID" + OtherId + "this.shOtherIndex" + this.shOtherIndex + "state" + state + "action" + action);
            if (this.repeatTable.get(new Long(OtherId)) != null) {
                 index = ((Integer) (this.repeatTable.get(new Long(OtherId)))).intValue();
                if (index != -1) {
                    this.refreshOther(index, OtherId, sex, (byte) -1, OtherName, Otherlv, hp, maxHp, mp, maxMp, state, action, directa, x, y, speed, pkpoint, tongname, duty);
                }
                return;
            }
            if (this.shOtherIndex >= Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN) {
                this.shOtherIndex = 0;
                while (this.shOtherIndex < Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN && this.shOtherIds[this.shOtherIndex] != -1) {
                    this.shOtherIndex++;
                }
            }
            if (this.shOtherIndex >= Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN) {
                return;
            }
            this.shOtherIds[this.shOtherIndex] = OtherId;
            this.byOtherJobs[this.shOtherIndex] = job;
            byOtherSex[this.shOtherIndex] = sex;
            this.repeatTable.put(new Long(OtherId), new Integer(this.shOtherIndex));
//            Tools.printLog("添加成功");
//            this.strOtherImgIds[this.shOtherIndex] = imgId;
            //#if NOKIA_S40V3 || MOTO || K790
//#   switch(sex)
//#             {
//#                 case Constant.PLAYER_SEX_WOMAN:
//#                     switch(job)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                              avatarId = 6000004;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                              avatarId = 6000002;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                               avatarId = 6000006;
//#                             break;
//#                     }
//#                 break;
//#                  case  Constant.PLAYER_SEX_MAN:
//#                       switch(job)
//#                     {
//#                         case Constant.PLAYER_OCCUPTION_ASSASSIN:
//#                             avatarId = 6000003;
//#                             break;
//#                             case Constant.PLAYER_OCCUPTION_SWORD:
//#                                 avatarId = 6000001;
//#                             break;
//#                              case Constant.PLAYER_OCCUPTION_MASTER:
//#                                     avatarId = 6000005;
//#                             break;
//#                     }
//#                 break;
//#             }
//#   this.strOtherResIds[this.shOtherIndex] =avatarId;
            //#else
             this.strOtherResIds[this.shOtherIndex] =avatarId;
            //#endif
            this.strOtherNames[this.shOtherIndex] = OtherName;
            if (tongname != null) {
                if (tongname.equals("")) {
                    this.strOtherTongNames[shOtherIndex] = null;
                } else if (tongname.substring(0, 1).equals(mark[0])) {
                    this.strOtherTongNames[shOtherIndex] = tongname;
                } else {
                    this.strOtherTongNames[shOtherIndex] = mark[0] + tongname + mark[1];
                }
            }
//            this.shOtherHps[this.shOtherIndex] = hp;
//            this.shOtherMaxHps[this.shOtherIndex] = maxHp;
//            this.shOtherMps[this.shOtherIndex] = mp;
//            this.shOtherMaxMps[this.shOtherIndex] = maxMp;
            this.iOtherXs[this.shOtherIndex] = x;
            this.iOtherYs[this.shOtherIndex] = y;
            this.iObjXs[this.shOtherIndex] = x;
            this.ObjYs[this.shOtherIndex] = y;
//            this.blOtherIsDie[this.shOtherIndex] = true;
//            this.shOtherLeves[this.shOtherIndex] = Otherlv;
            if (speed != -1) {
                this.shOtherSpeed[this.shOtherIndex] = (short) (speed / 12);
            }
//            if (avatarId == 50)//男武士
//            {
//                addAvatarAni(this.shOtherIndex, "51", Constant.PLAYER_AVATAR_WEAPON);
//            }
             //#if NOKIA_S40V3 || MOTO || K790
//#             ResManager.loadAnimation(avatarId, Constant.RES_PUBLIC_ONEROOM, false);
             //#else
               ResManager.loadAnimation(avatarId, Constant.RES_PUBLIC_ONEROOM, false);
             //#endif
            if (state == 3) {
//                Tools.printLog("玩家死亡啦");
                this.byOtherState[this.shOtherIndex] = Constant.PLAYER_STATE_DIE;
                byupdateOtherState[this.shOtherIndex] = -1;
            } else {
                this.changeAction(this.shOtherIndex, (byte) 0, action, directa);
                this.byupdateOtherState[this.shOtherIndex] = action;
            }
            this.byOtherDirection[this.shOtherIndex] = directa;
            this.changecolor(this.shOtherIndex, pkpoint);
            changeTongColor(shOtherIndex, duty);
            //                addAvatarAni(this.shOtherIndex, (short) 51, Constant.PLAYER_AVATAR_WEAPON);
            if (this.shOtherIndex < Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN) {
                this.shOtherIndex++;
                while (this.shOtherIndex < Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN && this.shOtherIds[this.shOtherIndex] != -1) {
                    this.shOtherIndex++;
                }
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
            Tools.printLog("异常");
        }
    }

    public void refreshOtherTongAndPk(long OtherId, int pkpoint, String tongname, byte duty) {
        int index = -1;
        if (this.repeatTable.get(new Long(OtherId)) == null) {
            return;
        } else {
            index = ((Integer) this.repeatTable.get(new Long(OtherId))).intValue();
        }
        if (tongname != null) {
            if (tongname.equals("")) {
                this.strOtherTongNames[index] = null;
            } else if (tongname.substring(0, 1).equals(mark[0])) {
                this.strOtherTongNames[index] = tongname;
            } else {
                this.strOtherTongNames[index] = mark[0] + tongname + mark[1];
            }
        }
        this.changecolor(index, pkpoint);
        changeTongColor(index, duty);
    }
    //刷新Other如果和当前状态和方向相同暂不更新坐标

    public void refreshOther(int index, long OtherId, byte sex, byte jobs, String OtherName, short Otherlv, short hp,
            short maxHp, short mp, short maxMp, byte state, byte action, byte direct, int x, int y, short speed, int pkpoint, String tongname, byte duty) {
//        Tools.printLog("收到其他玩家时间："+System.currentTimeMillis());
        if (state == 3) {
            this.byOtherState[index] = Constant.PLAYER_STATE_DIE;
            this.iObjXs[index] = x;
            this.ObjYs[index] = y;
            byupdateOtherState[index] = -1;
            Tools.printLog("其他玩家死亡：");
            return;
        }
//        Tools.printLog("refresh playername" + OtherName + "playerID" + OtherId + "state" + state + "action" + action);
        if (tongname != null) {
            if (tongname.equals("")) {
                this.strOtherTongNames[index] = null;
            } else if (tongname.substring(0, 1).equals(mark[0])) {
                this.strOtherTongNames[index] = tongname;
            } else {
                this.strOtherTongNames[index] = mark[0] + tongname + mark[1];
            }
        }
        if (action == Constant.PLAYER_STATE_RUN) {
            this.changeAction(index, state, action, direct);
            this.byOtherDirection[index] = direct;
        } else if (action == Constant.PLAYER_STATE_STAND) {
            if (this.byOtherState[index] == Constant.PLAYER_STATE_RUN) {
                this.byupdateOtherState[index] = action;
            } else {
                this.iOtherXs[index] = x;
                this.iOtherYs[index] = y;
                this.byupdateOtherState[index] = action;
                this.byOtherDirection[index] = direct;
                this.changeAction(index, state, action, direct);
            }
        } else if (action == Constant.PLAYER_STATE_FIGHT) {
            this.changeAction(index, state, action, direct);
            this.byOtherDirection[index] = direct;
        } else {
            this.byupdateOtherState[index] = action;
            this.byOtherDirection[index] = direct;
        }
        {
            this.iObjXs[index] = x;
            this.ObjYs[index] = y;
        }
        if (speed != -1) {
            this.shOtherSpeed[index] = (short) (speed / 12);
        }
        this.changecolor(index, pkpoint);
        changeTongColor(index, duty);
    }

    public void refreshPlayerWalk(long OtherId, byte state, byte action, byte direct, int x, int y) {
//        Tools.printLog("收到其他玩家时间："+System.currentTimeMillis());
        int index = -1;
        if (this.repeatTable.get(new Long(OtherId)) == null) {
            return;
        } else {
            index = ((Integer) this.repeatTable.get(new Long(OtherId))).intValue();
        }
        if (state == 3) {
            this.byOtherState[index] = Constant.PLAYER_STATE_DIE;
            this.iObjXs[index] = x;
            this.ObjYs[index] = y;
            byupdateOtherState[index] = -1;
            Tools.printLog("其他玩家死亡");
            return;
        }
//        Tools.printLog("refresh rNames" + strOtherNames[index] + "state" + state + "action" + action + "x" + x + "y" + y);
        if (action == Constant.PLAYER_STATE_RUN) {
            this.changeAction(index, state, action, direct);
        } else if (action == Constant.PLAYER_STATE_STAND) {
            if (this.byOtherState[index] == Constant.PLAYER_STATE_RUN) {
                this.changeAction(index, state, Constant.PLAYER_STATE_RUN, direct);
            } else {
//            Tools.printLog("refresh rNames" + direct);
//            this.iOtherXs[index] = x;
//            this.iOtherYs[index] = y;
//            this.changeActio/n(index, state, action, direct);
                this.byupdateOtherState[index] = action;
//            this.byOtherState[index] = action;
                this.byOtherDirection[index] = direct;
            }
        } else if (action == Constant.PLAYER_STATE_FIGHT) {

            this.changeAction(index, state, action, direct);
        }
//        this.byupdateOtherState[index] = action;
        {
            this.iObjXs[index] = x;
            this.ObjYs[index] = y;

        }
    }

    public void refreshPlayerTong(long OtherId, int pkpoint, String tongname, byte duty) {
        int index = -1;
        if (this.repeatTable.get(new Long(OtherId)) == null) {
            return;
        } else {
            index = ((Integer) this.repeatTable.get(new Long(OtherId))).intValue();
        }
        if (tongname.equals("")) {
            strOtherTongNames[index] = "";
        } else {
            strOtherTongNames[index] = mark[0] + tongname + mark[1];
        }
        changecolor(index, pkpoint);
        changeTongColor(index, duty);
    }

    public void deleteOther(int OtherIndex) {
        if (OtherIndex == -1 || this.repeatTable.get(new Long(this.shOtherIds[OtherIndex])) == null) {
            return;
        }
        if (shOtherIds[OtherIndex] == MainLogic.iLockedObjNumber[0][0]) {
            MainLogic.getInstance().clearLockedObj(0, true);
        }
        this.repeatTable.remove(new Long(this.shOtherIds[OtherIndex]));
        this.byOtherJobs[OtherIndex] = -1;
        byOtherSex[OtherIndex] = -1;
        this.shOtherIds[OtherIndex] = -1;
//        this.strOtherImgIds[OtherIndex] = null;
        this.strOtherResIds[OtherIndex] = -1;
        this.strOtherNames[OtherIndex] = null;
//        this.shOtherHps[OtherIndex] = -1;
//        this.shOtherMaxHps[OtherIndex] = -1;
//        this.shOtherMps[OtherIndex] = -1;
//        this.shOtherMaxMps[OtherIndex] = -1;
        this.byOtherState[OtherIndex] = -1;
        this.byOtherDirection[OtherIndex] = -1;
        this.iOtherXs[OtherIndex] = -1;
        this.iOtherYs[OtherIndex] = -1;
        this.iObjXs[OtherIndex] = -1;
        this.ObjYs[OtherIndex] = -1;
//        this.blOtherIsDie[OtherIndex] = false;
        this.shOtherSpeed[OtherIndex] = -1;
//        this.shPlayerOnePelsSpeedTime[OtherIndex] = -1;
        Tools.printLog("删除Other" + this.shOtherIds[OtherIndex]);
        this.deletePetsAni(OtherIndex);
    }

    public void checkOtherRun(int index) {
        if (this.byOtherState[index] == Constant.PLAYER_STATE_FIGHT || this.byOtherState[index] == Constant.PLAYER_STATE_DIE) {
            return;
        }
        if (this.iOtherYs[index] != this.ObjYs[index] || (this.iOtherXs[index] != this.iObjXs[index])) {
            if (this.byOtherState[index] != Constant.PLAYER_STATE_RUN) {
                byte direct = getMoveDirection(this.iOtherXs[index], this.iOtherYs[index], this.iObjXs[index], this.ObjYs[index]);
                if (direct != -1) {
                    this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_RUN, direct);
                }
            }
        } else {
            if (this.byOtherState[index] != Constant.PLAYER_STATE_STAND) {
                this.iOtherYs[index] = this.ObjYs[index];
                this.iOtherXs[index] = this.iObjXs[index];
                this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[index]);
            }
        }
    }

    public byte getDirection(int srcx, int srcy, int pointx, int pointy) {
//        Tools.printLog("playerx:" + this.iPlayerX + "playery:" + this.iPlayerY + "getdirectionx:" + pointx + "get directiony:" + pointy);
        int directx = srcx - pointx;
        int directy = srcy - pointy;
        if (directx == 0 && directy == 0) {
            return -1;
        }
        //玩家在目标右边
        if (directx > 0) {
            //玩家在目标下边
            if (directy > 0) {
                return (directx > directy) ? Constant.PLAYER_DIRECTION_LEFT : Constant.PLAYER_DIRECTION_UP;
            } else {
                return (directx > (-directy)) ? Constant.PLAYER_DIRECTION_LEFT : Constant.PLAYER_DIRECTION_DOWN;
            }
        } else//玩家在目标左边
        {
            //玩家在目标下边
            if (directy > 0) {
                return ((-directx) > directy) ? Constant.PLAYER_DIRECTION_RIGHT : Constant.PLAYER_DIRECTION_UP;
            } else {
                return ((-directx) > (-directy)) ? Constant.PLAYER_DIRECTION_RIGHT : Constant.PLAYER_DIRECTION_DOWN;
            }
        }
    }

    public byte getMoveDirection(int srcx, int srcy, int pointx, int pointy) {
//        Tools.printLog("playerx:" + this.iPlayerX + "playery:" + this.iPlayerY + "getdirectionx:" + pointx + "get directiony:" + pointy);
        int directx = srcx - pointx;
        int directy = srcy - pointy;
        if (directx == 0 && directy == 0) {
            return -1;
        }
        //玩家在目标右边
        if (directx > 0) {
            //玩家在目标下边
            return Constant.PLAYER_DIRECTION_LEFT;
        } else if (directx < 0)//玩家在目标左边
        {
            return Constant.PLAYER_DIRECTION_RIGHT;
        }

        if (directy > 0) {
            return Constant.PLAYER_DIRECTION_UP;
        } else if (directy < 0) {
            return Constant.PLAYER_DIRECTION_DOWN;
        }
        return -1;
    }
    //更新Other

    public void updateOther() {
        for (int i = Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN - 1; i >= 0; i--) {
            if (shOtherIds[i] != -1) {
                checkOtherRun(i);
                switch (this.byOtherState[i]) {
                    case Constant.PLAYER_STATE_RUN:
                        this.lCurrentTime[i] = System.currentTimeMillis();
                        this.otherRun(i);
                        break;
                    case Constant.PLAYER_STATE_FIGHT:
                        if (this.iNpcAniPre[i][4] == 1) {
                            this.changeAction(i, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[i]);
                        }
                        break;
                }
//                if (byupdateOtherState[i] != -1) {
//                    this.byOtherState[i] = byupdateOtherState[i];
//                    this.byupdateOtherState[i] = -1;
//                }
                //更新宠物
                this.updatePetShow(i);
            }
        }
    }

    public void otherRun(int index) {
        if (this.shOtherSpeed[index] <= 0) {
            return;
        }
//        int iStep = 0;
//        //1秒内持续时间 = （当前时间 - 走路开始时间）
//
//        //到1秒了如果走到距离不到48像素强行职位到48像素变向的误差不计
//        if ((this.lCurrentTime[index] - this.lStartTime[index]) > 1000L) {
//            this.lStartTime[index] = this.lCurrentTime[index];
//            iStep = this.iMoveDistance[index] - 48;
//            this.iMoveDistance[index] = 0;
//        } else {
////走路间隔时间
////           long walktime = this.iContinueTime - this.lStartTime;
////        if (lDelayTime2 >= this.shPlayerOnePelsSpeedTime)
////            {
//            if (this.iMoveDistance[index] > 48) {
//                iStep = 0;
//            } else if (this.iMoveDistance[index] == 0) {
//                iStep = 4;
//                this.iMoveDistance[index] = 4;
//            } else {
//                this.shPlayerOnePelsSpeedTime[index] = (short) ((1000 - (this.lUpdateTime[index] - this.lStartTime[index])) / (48 - this.iMoveDistance[index]));
//                iStep = (int) ((this.lCurrentTime[index] - this.lUpdateTime[index]) / this.shPlayerOnePelsSpeedTime[index]);
//                this.lUpdateTime[index] = System.currentTimeMillis();
//                this.iMoveDistance[index] += iStep;
//            }
////            this.lWalkTime += iStep * this.shPlayerOnePelsSpeedTime;
//        }
//        Tools.printLog("人物走动：this.iMoveDistance：" + "index:" + this.iMoveDistance[index] + "iStep:" + iStep + "shPlayerOnePelsSpeedTime:" + shPlayerOnePelsSpeedTime[index]);
        int iStep = this.shOtherSpeed[index];
        //是否切换场景
        boolean blChangeScene = false;
        if (iStep <= 0) {
            return;
        }
//测试  getDirection
        byte direct = getMoveDirection(this.iOtherXs[index], this.iOtherYs[index], this.iObjXs[index], this.ObjYs[index]);
        if (direct != -1 && direct != this.byOtherDirection[index]) {
            this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_RUN, direct);
            this.byOtherDirection[index] = direct;
        }

        switch (this.byOtherDirection[index]) {
            case Constant.PLAYER_DIRECTION_UP: //                if (this.iOtherYs[index] <= this.ObjYs[index])
            {
                this.iOtherYs[index] -= iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_DOWN: //                if (this.iOtherYs[index] >= this.ObjYs[index])
            {
                this.iOtherYs[index] += iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_LEFT: //                if (this.iOtherXs[index] <= this.iObjXs[index])
            {
                this.iOtherXs[index] -= iStep;
            }
            break;
            case Constant.PLAYER_DIRECTION_RIGHT: //                if (this.iOtherXs[index] >= this.iObjXs[index])
            {
                this.iOtherXs[index] += iStep;
            }
            break;
        }
        /******************************测试*************************/
        switch (this.byOtherDirection[index]) {
            case Constant.PLAYER_DIRECTION_UP:
                if (this.iOtherYs[index] <= this.ObjYs[index]) {
                    this.iOtherYs[index] = this.ObjYs[index];
                    if (this.byupdateOtherState[index] == Constant.PLAYER_STATE_STAND) {
                        this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[index]);
                        this.byOtherState[index] = Constant.PLAYER_STATE_STAND;
                        this.byupdateOtherState[index] = -1;
                    }
                }

                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                if (this.iOtherYs[index] >= this.ObjYs[index]) {
                    this.iOtherYs[index] = this.ObjYs[index];
                    if (this.byupdateOtherState[index] == Constant.PLAYER_STATE_STAND) {
                        this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[index]);
                        this.byOtherState[index] = Constant.PLAYER_STATE_STAND;
                        this.byupdateOtherState[index] = -1;
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (this.iOtherXs[index] <= this.iObjXs[index]) {
                    this.iOtherXs[index] = this.iObjXs[index];
                    if (this.byupdateOtherState[index] == Constant.PLAYER_STATE_STAND) {
                        this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[index]);
                        this.byOtherState[index] = Constant.PLAYER_STATE_STAND;
                        this.byupdateOtherState[index] = -1;
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (this.iOtherXs[index] >= this.iObjXs[index]) {
                    this.iOtherXs[index] = this.iObjXs[index];
                    if (this.byupdateOtherState[index] == Constant.PLAYER_STATE_STAND) {
                        this.changeAction(index, (byte) 0, Constant.PLAYER_STATE_STAND, this.byOtherDirection[index]);
                        this.byOtherState[index] = Constant.PLAYER_STATE_STAND;
                        this.byupdateOtherState[index] = -1;
                    }
                }
                break;
        }
    }

    public void drawOther(Graphics g, int i, int x, int y) {
        boolean blContinue = true;
        if (this.shOtherIds[i] != -1)//&&this.blOtherResInitOver[i])
        {
//              Tools.printLog("其他玩家状态"+this.byOtherState[i]);
            if ((MainLogic.getInstance().uiInterFace.team.getMemberPos(this.shOtherIds[i]) == -1)
                    && !MainLogic.getInstance().uiEquipment.isopenset[20]) {
            } else {
                if (this.byOtherState[i] == Constant.PLAYER_STATE_DIE) {
                    Player.showPlayerDie(g, this.iOtherXs[i] - x, this.iOtherYs[i] - y);
                } else {
                    if (MainLogic.getInstance().uiEquipment.isopenset[21]) {
                        if (this.byOtherState[i] == Constant.PLAYER_STATE_FIGHT) {
                            blContinue = false;
                        } else {
                            blContinue = true;
                        }
                        if (MainLogic.getInstance().uiEquipment.isopenset[17]) {
                            g.drawImage(MainView.imgShadow, this.iOtherXs[i] - x - 16, this.iOtherYs[i] - y - 10, 0);
                        }
                        if (this.shOtherIds[i] == MainLogic.iLockedObjNumber[0][0]) {
//                    MainLogic.getInstance().drawLockedObj(g, (this.iOtherXs[i] - x), (this.iOtherYs[i] - y));
                            if (Math.abs(MainLogic.getInstance().gamePlayer.iPlayerX - this.iOtherXs[i]) > MainLogic.getInstance().iLockedOtherplayerW
                                    || Math.abs(MainLogic.getInstance().gamePlayer.iPlayerY - this.iOtherYs[i]) > MainLogic.getInstance().iLockedOtherplayerH) {
                                MainLogic.getInstance().isLocked = true;
                            } else {
                                MainLogic.iLockedObjNumber[0][2] = this.iOtherXs[i];
                                MainLogic.iLockedObjNumber[0][3] = this.iOtherYs[i];
                            }
                        }
                        //男
                         if(this.strOtherResIds[i] !=  Constant.RES_PLAYER_MAN_ANI_PATH&&this.strOtherResIds[i] !=  Constant.RES_PLAYER_WOMEN_ANI_PATH)
                        ResManager.drawAnimation(ResManager.getAnimation(this.strOtherResIds[i], (byte) -1), this.iNpcAniPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                                else
        {
            if(this.byOtherJobs[i] == Constant.PLAYER_OCCUPTION_MASTER&&(this.byOtherDirection[i] == Constant.PLAYER_DIRECTION_LEFT||this.byOtherDirection[i]== Constant.PLAYER_DIRECTION_RIGHT))
            {
                 if(this.byOtherState[i] == Constant.PLAYER_STATE_RUN||this.byOtherState[i] == Constant.PLAYER_STATE_STAND)
                 {
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarWeapon[i], (byte) -1), this.ianiAvatarWeaponPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.strOtherResIds[i], (byte) -1), this.iNpcAniPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                  ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarShoes[i], (byte) -1),  this.ianiAvatarShoesPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarTrousers[i], (byte) -1), this.ianiAvatarTrousersPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear[i], (byte) -1), this.ianiAvatarHear[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead[i],(byte) -1), this.ianiAvatarHead[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarCloes[i],(byte) -1), this.ianiAvatarCloesPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                }
           else{
                ResManager.drawAnimation(ResManager.getAnimation(this.strOtherResIds[i], (byte) -1), this.iNpcAniPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarShoes[i], (byte) -1),  this.ianiAvatarShoesPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarTrousers[i], (byte) -1), this.ianiAvatarTrousersPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear[i], (byte) -1),this.ianiAvatarHear[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead[i], (byte) -1), this.ianiAvatarHead[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarCloes[i], (byte) -1), this.ianiAvatarCloesPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarWeapon[i], (byte) -1), ianiAvatarWeaponPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                }
            }
            else
            {
            if((this.byOtherState[i] == Constant.PLAYER_STATE_RUN||this.byOtherState[i] == Constant.PLAYER_STATE_STAND) && this.byOtherDirection[i] != Constant.PLAYER_DIRECTION_UP)
            {
                ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarWeapon[i],(byte) -1), ianiAvatarWeaponPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.strOtherResIds[i], (byte) -1), this.iNpcAniPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
               ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarShoes[i], (byte) -1),  this.ianiAvatarShoesPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarCloes[i], (byte) -1), this.ianiAvatarCloesPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarTrousers[i], (byte) -1), this.ianiAvatarTrousersPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear[i], (byte) -1), this.ianiAvatarHear[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
               ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead[i], (byte) -1), this.ianiAvatarHead[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                }
            else
            {
             
                ResManager.drawAnimation(ResManager.getAnimation(this.strOtherResIds[i], (byte) -1), this.iNpcAniPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                 ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarShoes[i], (byte) -1),  this.ianiAvatarShoesPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
               ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarCloes[i], (byte) -1), this.ianiAvatarCloesPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
               ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarTrousers[i], (byte) -1), this.ianiAvatarTrousersPre[i], g,this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
              ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHear[i], (byte) -1), this.ianiAvatarHear[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
                ResManager.drawAnimation(ResManager.getAnimation(aniAvatarHead[i], (byte) -1),this.ianiAvatarHead[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);;
               ResManager.drawAnimation(ResManager.getAnimation(this.aniAvatarWeapon[i], (byte) -1), ianiAvatarWeaponPre[i], g, this.iOtherXs[i] - x, this.iOtherYs[i] - y, blContinue);
            }
            }

        }
                            if (this.iPetAniID[i] != -1) {
                            ResManager.drawAnimation(ResManager.getAnimation(this.iPetAniID[i], Constant.RES_PUBLIC_ONEROOM), this.ianiPetPre[i], g, iPetX[i] - x, iPetY[i] - y, true);
//                    ResManager.drawAnimation(ResManager.getAnimation(this.iPetsAniId, Constant.RES_PUBLIC_ONEROOM), this.iNpcAniPre[5], g, iPetX - x, iPetY - y, true);
                        }
                    }
                      
                    if (MainLogic.getInstance().uiEquipment.isopenset[13]) {
                        if (this.strOtherTongNames[i] == null) {//判断有没有帮派代号
                            Tools.drawShadowString(g, (byte) 0, this.strOtherNames[i], this.iOtherXs[i] - x
                                    - (Constant.FONT_SMALL.stringWidth(this.strOtherNames[i]) >> 1),
                                    this.iOtherYs[i] - y - 80, this.iNameColor[i], 0x333333);
                        } else {
                            Tools.drawShadowString(g, (byte) 0, this.strOtherTongNames[i], this.iOtherXs[i] - x
                                    - (Constant.FONT_SMALL.stringWidth(this.strOtherNames[i]
                                    + this.strOtherTongNames[i]) >> 1), this.iOtherYs[i] - y - 80, iTongColor[i], 0x333333);
                            Tools.drawShadowString(g, (byte) 0, this.strOtherNames[i], this.iOtherXs[i] - x
                                    - (Constant.FONT_SMALL.stringWidth(this.strOtherNames[i]
                                    + this.strOtherTongNames[i]) >> 1) + Constant.FONT_SMALL.stringWidth(this.strOtherTongNames[i]),
                                    this.iOtherYs[i] - y - 80, this.iNameColor[i], 0x333333);
                        }
                    }
                    if (MainLogic.getInstance().uiEquipment.isopenset[21]) {
                        if (this.sPetNick[i] != null) {
                            g.drawString(this.sPetNick[i], iPetX[i] - x - (Constant.FONT_SMALL.stringWidth(this.sPetNick[i]) >> 1), iPetY[i] - y - shPetHeight[i] - Constant.FONT_SMALL_HEIGHT - 2, 0);
                        }

                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101")
                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                            if (strOtherTongNames[i] == null || !MainLogic.getInstance().gamePlayer.sTongName.equals(strOtherTongNames[i])) {//不同阵营
                                g.drawImage(MainLogic.getInstance().uiInterFace.otherPlayerFlag[1],
                                        iOtherXs[i] - x - (MainLogic.getInstance().uiInterFace.otherPlayerFlag[1].getWidth() >> 1),
                                        iOtherYs[i] - y - 80 - MainLogic.getInstance().uiInterFace.otherPlayerFlag[1].getHeight(), 0);
                            } else {//同一阵营
                                g.drawImage(MainLogic.getInstance().uiInterFace.otherPlayerFlag[0],
                                        iOtherXs[i] - x - (MainLogic.getInstance().uiInterFace.otherPlayerFlag[0].getWidth() >> 1),
                                        iOtherYs[i] - y - 80 - MainLogic.getInstance().uiInterFace.otherPlayerFlag[0].getHeight(), 0);
                            }
                        }
                    }
                }
            }
        }
    }

    private void changeAvatarAction(int index, int action) {
//        Tools.printLog("index"+index);
        ResManager.changeAction(ResManager.getAnimation(this.strOtherResIds[index], (byte) -1), action, 0, this.iNpcAniPre[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarShoes[index], (byte) -1), action, 0, this.ianiAvatarShoesPre[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarTrousers[index], (byte) -1), action, 0, this.ianiAvatarTrousersPre[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarCloes[index], (byte) -1), action, 0, this.ianiAvatarCloesPre[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarWeapon[index], (byte) -1), action, 0, this.ianiAvatarWeaponPre[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarHear[index], (byte) -1), action, 0, this.ianiAvatarHear[index]);
        ResManager.changeAction(ResManager.getAnimation(this.aniAvatarHead[index], (byte) -1), action, 0, this.ianiAvatarHead[index]);
    }

    public boolean avatarChangeact(int index) {
        if (ResManager.getAnimation(this.aniAvatarShoes[index], (byte) -1) != null) {
            if (this.ianiAvatarShoesPre[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
        if (ResManager.getAnimation(this.aniAvatarTrousers[index], (byte) -1) != null) {
            if (this.ianiAvatarTrousersPre[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
        if (ResManager.getAnimation(this.aniAvatarCloes[index], (byte) -1) != null) {
            if (this.ianiAvatarCloesPre[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
        if (ResManager.getAnimation(this.aniAvatarWeapon[index], (byte) -1) != null) {
            if (this.ianiAvatarWeaponPre[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
         if (ResManager.getAnimation(this.aniAvatarHear[index], (byte) -1) != null) {
            if (this.ianiAvatarHear[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
          if (ResManager.getAnimation(this.aniAvatarHead[index], (byte) -1) != null) {
            if (this.ianiAvatarHead[index][1] == this.iNpcAniPre[index][1]) {
                return true;
            } else {
                return false;
            }
        }
        return true;
    }

    public void changeAction(int index, byte state, byte cursAct, byte direct) {
        try {
            if (this.byOtherState[index] == cursAct && this.byOtherDirection[index] == direct) {
                if (avatarChangeact(index)) {
                    return;
                }
            }
            this.byupdateOtherState[index] = cursAct;
            this.byOtherState[index] = cursAct;
            this.byOtherDirection[index] = direct;
            for (int i = 0; i < 5; i++) {
                this.iNpcAniPre[index][i] = 0;
                this.ianiAvatarShoesPre[index][i] = 0;
                this.ianiAvatarCloesPre[index][i] = 0;
                this.ianiAvatarTrousersPre[index][i] = 0;
                this.ianiAvatarWeaponPre[index][i] = 0;
                this.ianiAvatarHear[index][i] = 0;
                this.ianiAvatarHead [index][i] = 0;
//                this.ianiPetPre[index][i] = 0;
            }
            switch (cursAct) {
                case Constant.PLAYER_STATE_STAND:
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_UP:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_UP_STAND);
                            break;
                        case Constant.PLAYER_DIRECTION_DOWN:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_DOWN_STAND);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_LEFT_STAND);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_RIGHT_STAND);
                            break;
                    }
                    break;
                case Constant.PLAYER_STATE_RUN:
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_UP:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_UP_RUN);
                            break;
                        case Constant.PLAYER_DIRECTION_DOWN:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_DOWN_RUN);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_LEFT_RUN);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_RIGHT_RUN);
                            break;
                    }
                    break;
                case Constant.PLAYER_STATE_FIGHT:
                    switch (direct) {
                        case Constant.PLAYER_DIRECTION_DOWN:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_DOWN_FIGHT);
                            break;
                        case Constant.PLAYER_DIRECTION_UP:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_UP_FIGHT);
                            break;
                        case Constant.PLAYER_DIRECTION_LEFT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_LEFT_FIGHT);
                            break;
                        case Constant.PLAYER_DIRECTION_RIGHT:
                            this.changeAvatarAction(index, Constant.PLAYER_ACTION_ID_RIGHT_FIGHT);
                            break;
                    }
                    break;
                default:
                    if (state == Constant.PLAYER_BIG_STATE_FIGHT) {
                        this.byupdateOtherState[index] = Constant.PLAYER_STATE_FIGHT;
                        switch (direct) {
                            case Constant.PLAYER_DIRECTION_UP:
                                cursAct += 1;
                                break;
                            case Constant.PLAYER_DIRECTION_LEFT:
                                cursAct += 2;
                                break;
                            case Constant.PLAYER_DIRECTION_RIGHT:
                                cursAct += 3;
                                break;
                        }
                        this.changeAvatarAction(index, cursAct);
                        this.byupdateOtherState[index] = -1;
                    }
                    break;
            }
            if (cursAct == Constant.PLAYER_STATE_RUN) {
                this.lStartTime[index] = this.lUpdateTime[index] = System.currentTimeMillis();
                this.iMoveDistance[index] = 0;
            }
        } catch (Exception e) {
            if (Constant.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    public boolean bltempceshi = false;
    /*****
     * 其他玩家的宠物
     */
    /**
     * 设置宠物动画
     */
    //宠物动画的坐标
    public int iPetX[];
    public int iPetY[];
    //宠物移动的目标位置
    public int iPetDestX[];
    public int iPetDestY[];
    //是否已经开始向目标方向移动了
    public boolean bStartMoveToDest[];
    public long lStopStartTime[];
    //宠物的方向
    public byte byPetDirection[];
    //宠物停留的时间
    public int iPetStopTime[];
    //移动到目标点后是停留还是继续移动
    public boolean bStandNextTime[];
    public byte byPetSpeed[];
    //宠物和角色的相对状态
    //玩家站立不动,宠物在玩家的周围智能移动 0
    //玩家站立不动，宠物还向着玩家的方向移动 1:
    //玩家移动，宠物不动  2
    //玩家移动，宠物也移动 3
    public byte byPetStatus[];
    public static int iPetMaxOffset = 60;//宠物的活动矩形半径
    public static int iPetMinAIOffset = 15;//宠物的随机点最小间距
    public static String sPetNick[];
    public static short shPetHeight[];
    public int[] iPetAniID;

    public void addPetsAni(int index, int avatarId, String sPetName, short shPetHeight) {
        this.sPetNick[index] = sPetName;
        if (this.iPetAniID[index] == avatarId) {
            return;
        }
        this.iPetAniID[index] = avatarId;
        ResManager.loadAnimation(avatarId, Constant.RES_PUBLIC_ONEROOM, true);
        bStartMoveToDest[index] = false;
        this.bStandNextTime[index] = false;
        lStopStartTime[index] = System.currentTimeMillis();
        iPetStopTime[index] = Tools.random(3000, 5000);
        this.byPetDirection[index] = this.byOtherDirection[index];
        this.iPetX[index] = this.iOtherXs[index] + iPetMaxOffset - 10;
        this.iPetY[index] = this.iOtherYs[index];
        this.shPetHeight[index] = shPetHeight;
        this.updatePetSatus(index);
        switch (this.byOtherState[index]) {
            case Constant.PLAYER_STATE_STAND:
            case Constant.PLAYER_STATE_FIGHT:
            case Constant.PLAYER_STATE_FIGHT_READY:
                //状态没有发生变化
                this.byPetStatus[index] = 0;
                this.setNextRodamPlace(index);
                return;
            case Constant.PLAYER_STATE_RUN:
            case Constant.PLAYER_STATE_AUTO_RUN:
                //玩家开始移动
                this.byPetStatus[index] = 3;
                this.getTransXY(index);
                break;
            default:
                this.byPetStatus[index] = 0;
                this.setNextRodamPlace(index);
                break;
        }
    }

    /**
     * 删除宠物
     */
    public void deletePetsAni(int index) {
        this.iPetAniID[index] = -1;
        this.sPetNick[index] = null;
    }

    /**
     * 不同状态下宠物的移动
     * @param Direction 移动方向
     */
    public void petMove(byte Direction, int index) {
        boolean bChange = false;
        switch (Direction) {
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (this.iPetDestX[index] > this.iPetX[index]) {
                    //向右走路中
                    this.iPetX[index] += byPetSpeed[index];
                } else {
                    this.iPetX[index] = this.iPetDestX[index];
                    //向右走停止,判读是否需要寻找下个目标点
                    if (this.iPetDestY[index] == this.iPetY[index]) {
                        bChange = true;
                    } else {
                        //改变方向
                        this.changePetDirection((byte) 2, index);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                //"向左走/
                if (this.iPetDestX[index] < this.iPetX[index]) {
                    //向左走路中/
                    this.iPetX[index] -= byPetSpeed[index];
                } else {
                    //向左走停止,改变方向/
                    //判读是否需要寻找下个目标点
                    this.iPetX[index] = this.iPetDestX[index];
                    if (this.iPetDestY[index] == this.iPetY[index]) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 2, index);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_DOWN:
                //向下走
                if (this.iPetDestY[index] > this.iPetY[index]) {
                    //向下走路中
                    this.iPetY[index] += byPetSpeed[index];
                } else {
                    //向下走路停止,寻找下个目标点
                    this.iPetY[index] = this.iPetDestY[index];
                    if (this.iPetDestX[index] == this.iPetX[index]) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 1, index);
                    }
                }
                break;
            case Constant.PLAYER_DIRECTION_UP:
                //向上走
                if (this.iPetDestY[index] < this.iPetY[index]) {
                    //向上走路中
                    this.iPetY[index] -= byPetSpeed[index];
                } else {
                    //向上走路停止,寻找下个目标点
                    this.iPetY[index] = this.iPetDestY[index];
                    if (this.iPetDestX[index] == this.iPetX[index]) {
                        bChange = true;
                    } else {
                        this.changePetDirection((byte) 1, index);
                    }
                }
                break;
        }
        if (bChange) {
            switch (this.byPetStatus[index]) {
                case 0:
                    this.setNextRodamPlace(index);
                    break;
                case 1:
                    this.initPetStatus(index);
                    break;
                case 2:
                    break;
                case 3:
                    this.getTransXY(index);
                    break;
            }
        }
    }

    /**
     * 更新宠物状态和坐标
     */
    public void updatePetShow(int i) {
        //先考虑玩家站立不动的状态下的情况
//        Tools.printLog("this.iPetAniID[" + i + "]=" + this.iPetAniID[i]);
        if (this.iPetAniID[i] == -1) {
            return;
        }
//        if (MainCanvas.fps > 0) {
//            this.byPetSpeed[i] = (byte) (this.shOtherSpeed[i] / MainCanvas.fps);
//        } else {
        this.byPetSpeed[i] = 2;
        //}
//        Tools.printLog("this.byPetSpeed[" + i + "]=" + this.byPetSpeed[i]);
        switch (this.byPetStatus[i]) {
            case 0:
                //玩家站立不动,宠物在玩家的周围智能移动 0
                if (!bStartMoveToDest[i]) {
                    //逗留时间段
                    if (System.currentTimeMillis() - lStopStartTime[i] > iPetStopTime[i]) {
                        //寻找下个目标点或是继续停留
                        this.setNextRodamPlace(i);
                    }
                    //停留中
                } else {
                    this.petMove(this.byPetDirection[i], i);
                }
                break;
            case 1:
            //玩家站立不动，宠物还向着玩家的方向移动 1:
            //this.petMove(this.byPetDirection);
            //break;
            case 3:
                //玩家移动，宠物也移动 3
                //先判读玩家和宠物的方向距离
                this.petMove(this.byPetDirection[i], i);
                break;
            case 2:
                //玩家移动，宠物不动  2
                //不用操作
                break;
        }
        this.updatePetSatus(i);
    }

    /**
     * 设置下次的随机地址
     */
    public void setNextRodamPlace(int index) {
        if (this.bStandNextTime[index]) {
            bStartMoveToDest[index] = false;
            lStopStartTime[index] = System.currentTimeMillis();
            iPetStopTime[index] = Tools.random(3000, 5000);
            this.bStandNextTime[index] = Tools.random(0, 1) == 1 ? true : false;
            this.chanagePetAction(this.byPetDirection[index], index, (byte) 0);
        } else {
            bStartMoveToDest[index] = true;
            lStopStartTime[index] = 0L;
            //下个目标点位置
            this.iPetDestX[index] = Tools.getNpcRodamXY(this.iOtherXs[index], this.iPetX[index], iPetMaxOffset, iPetMinAIOffset);
            this.iPetDestY[index] = Tools.getNpcRodamXY(this.iOtherYs[index], this.iPetY[index], iPetMaxOffset, iPetMinAIOffset);
            this.bStandNextTime[index] = Tools.random(0, 1) == 1 ? true : false;
            //下次是停留还是继续移动
            //改变宠物的状态
            //根据xy哪个距离短就开始走哪个
            if (Math.abs(this.iPetDestX[index] - this.iPetX[index]) >= Math.abs(this.iPetDestY[index] - this.iPetY[index])) {
                this.changePetDirection((byte) 1, index);
            } else {
                this.changePetDirection((byte) 2, index);
            }
        }

    }

    /**
     * 改变宠物走路的方向
     */
    public void changePetDirection(byte byDirection, int index) {
        //改变宠物移动的方向
        switch (byDirection) {
            case 1:
                if (this.iPetDestX[index] > this.iPetX[index]) {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_RIGHT, index, (byte) 1);
                } else {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_LEFT, index, (byte) 1);
                }
                break;
            case 2:
                if (this.iPetDestY[index] > this.iPetY[index]) {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_DOWN, index, (byte) 1);
                } else {
                    this.chanagePetAction(Constant.PLAYER_DIRECTION_UP, index, (byte) 1);

                }
                break;
        }
    }

    public void initPetStatus(int index) {
        switch (this.byPetStatus[index]) {
            case 0:
                // Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.bStandNextTime[index] = false;
                this.setNextRodamPlace(index);
                break;
            case 1:
                //Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.iPetDestX[index] = this.iOtherXs[index];
                this.iPetDestY[index] = this.iOtherYs[index];
                if (Math.abs(this.iPetDestX[index] - this.iPetX[index]) >= Math.abs(this.iPetDestY[index] - this.iPetY[index])) {
                    this.changePetDirection((byte) 1, index);
                } else {
                    this.changePetDirection((byte) 2, index);
                }
                break;
            case 2:
                //Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.chanagePetAction(this.byOtherDirection[index], index, (byte) 0);
                break;
            case 3:
                // Tools.printLog("宠物状态更新为:" + this.byPetStatus);
                this.getTransXY(index);
                break;

        }
        Tools.printLog("this.byPetStatus= " + this.byPetStatus[index]);
    }

    /**
     * 更新宠物的状态
     */
    public void updatePetSatus(int index) {
        int length = Tools.square(this.iPetX[index] - this.iOtherXs[index]) + Tools.square(this.iPetY[index] - this.iOtherYs[index]);
        int iMaxLength = 25600;
        if (length > iMaxLength) {
            //如果宠物离人的距离太远，就瞬移到人物背后
            this.byPetDirection[index] = this.byOtherDirection[index];
            switch (this.byOtherDirection[index]) {
                case Constant.PLAYER_DIRECTION_DOWN:
                    this.iPetX[index] = this.iOtherXs[index];
                    this.iPetY[index] = this.iOtherYs[index] - (this.iPetMaxOffset - 5);
                    break;
                case Constant.PLAYER_DIRECTION_UP:
                    this.iPetX[index] = this.iOtherXs[index];
                    this.iPetY[index] = this.iOtherYs[index] + (this.iPetMaxOffset - 5);
                    break;
                case Constant.PLAYER_DIRECTION_LEFT:
                    this.iPetX[index] = this.iOtherXs[index] + (this.iPetMaxOffset - 5);
                    this.iPetY[index] = this.iOtherYs[index];
                    break;
                case Constant.PLAYER_DIRECTION_RIGHT:
                    this.iPetX[index] = this.iOtherXs[index] - (this.iPetMaxOffset - 5);
                    this.iPetY[index] = this.iOtherYs[index];
                    break;
            }
            this.byPetStatus[index] = 2;
            this.initPetStatus(index);
            return;
        }
        //宠物状态的改变
        switch (this.byPetStatus[index]) {
            case 0:
                //玩家站立不动,宠物在玩家的周围智能移动 0
                switch (this.byOtherState[index]) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //玩家开始移动
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus[index] = 3;
                            this.initPetStatus(index);
                        } else {
                            this.byPetStatus[index] = 2;
                            this.initPetStatus(index);
                        }
                        break;
                }
                break;
            case 1:
                //玩家站立不动，宠物还向着玩家的方向移动 1:
                switch (this.byOtherState[index]) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus[index] = 0;
                            this.initPetStatus(index);
                        } else {
                            //不做变化
                        }
                        break;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //玩家开始移动
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus[index] = 3;
                            this.initPetStatus(index);
                        } else {
                            this.byPetStatus[index] = 2;
                            this.initPetStatus(index);
                        }
                        break;
                }
                break;
            case 2:
                //玩家移动，宠物不动  2
                switch (this.byOtherState[index]) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus[index] = 0;
                            this.initPetStatus(index);
                        } else {
                            this.byPetStatus[index] = 1;
                            this.initPetStatus(index);
                        }
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        if (length >= this.iPetMaxOffset) {
                            this.byPetStatus[index] = 3;
                            this.initPetStatus(index);
                        } else {
                            //不做改变
                            //this.byPetStatus = 2;
                        }
                        break;
                }
                break;
            case 3:
                //玩家移动，宠物也移动 3
                switch (this.byOtherState[index]) {
                    case Constant.PLAYER_STATE_STAND:
                    case Constant.PLAYER_STATE_FIGHT:
                    case Constant.PLAYER_STATE_FIGHT_READY:
                        //状态没有发生变化
                        if (length < this.iPetMaxOffset) {
                            this.byPetStatus[index] = 0;
                            this.initPetStatus(index);
                        } else {
                            this.byPetStatus[index] = 1;
                            this.initPetStatus(index);
                        }
                        return;
                    case Constant.PLAYER_STATE_RUN:
                    case Constant.PLAYER_STATE_AUTO_RUN:
                        //不做变化
                        break;
                }
                break;
        }
    }

    /**
     * 获得宠物和玩家中间的一个点
     * @param iCurrX
     * @param iCurrY
     * @param terminalX
     * @param terminalY
     */
    public void getTransXY(int index) {
        if (this.iPetX[index] > this.iOtherXs[index]) {
            //向右
            this.iPetDestX[index] = this.iPetX[index] - Math.abs(this.iOtherXs[index] - this.iPetX[index]) / 3;
        } else {
            this.iPetDestX[index] = this.iPetX[index] + Math.abs(this.iOtherXs[index] - this.iPetX[index]) / 3;
        }
        if (this.iPetY[index] > this.iOtherYs[index]) {
            //向右
            this.iPetDestY[index] = this.iPetY[index] - Math.abs(this.iOtherYs[index] - this.iPetY[index]) / 3;
        } else {
            this.iPetDestY[index] = this.iPetY[index] + Math.abs(this.iOtherYs[index] - this.iPetY[index]) / 3;
        }
        //根据xy哪个距离短就开始走哪个
        if (Math.abs(this.iPetDestX[index] - this.iPetX[index]) >= Math.abs(this.iPetDestY[index] - this.iPetY[index])) {
            this.changePetDirection((byte) 1, index);
        } else {
            this.changePetDirection((byte) 2, index);
        }

    }

    public void chanagePetAction(byte byDirection, int index, byte state) {
        if (this.iPetAniID == null) {
            return;
        }
        Tools.resetAniArray(0, this.ianiPetPre[index]);
        this.byPetDirection[index] = byDirection;
        switch (byDirection) {
            case Constant.PLAYER_DIRECTION_DOWN:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_DOWN_STAND, 0, this.ianiPetPre[index]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_DOWN_RUN, 0, this.ianiPetPre[index]);
                }
                break;
            case Constant.PLAYER_DIRECTION_UP:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_UP_STAND, 0, this.ianiPetPre[index]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_UP_RUN, 0, this.ianiPetPre[index]);
                }
                break;
            case Constant.PLAYER_DIRECTION_LEFT:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_LEFT_STAND, 0, this.ianiPetPre[index]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_LEFT_RUN, 0, this.ianiPetPre[index]);
                }
                break;
            case Constant.PLAYER_DIRECTION_RIGHT:
                if (state == 0) {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_RIGHT_STAND, 0, this.ianiPetPre[index]);
                } else {
                    ResManager.changeAction(ResManager.getAnimation(this.iPetAniID[index], Constant.RES_PUBLIC_ONEROOM), Constant.PLAYER_ACTION_ID_RIGHT_RUN, 0, this.ianiPetPre[index]);
                }
                break;
        }
    }

    public void clearOtherPlayer() {
        // Tools.printLog("清理其他玩家");
        this.repeatTable = new Hashtable();
        for (int i = Constant.MAX_OTHERPLAYER_NUM_IN_SCREEN - 1; i >= 0; i--) {
            this.shOtherIds[i] = -1;
            this.strOtherNames[i] = null;
            this.strOtherTongNames[i] = null;
//            this.shOtherLeves[i] = -1;
            this.strOtherResIds[i] = -1;
            this.iOtherXs[i] = -1;
            this.iOtherYs[i] = -1;
            this.iObjXs[i] = -1;
            this.ObjYs[i] = -1;
            this.byOtherState[i] = -1;
            this.byupdateOtherState[i] = -1;
            this.byOtherDirection[i] = -1;
            this.shOtherSpeed[i] = -1;
            //当前时间
            this.lCurrentTime[i] = -1;
            //和服务器时间差
            //本地走路开始时间
            this.lStartTime[i] = -1;
            //走路持续时间
            this.iContinueTime[i] = -1;
            this.iMoveDistance[i] = -1;
            this.lUpdateTime[i] = -1;
            this.iPkPoint[i] = 0;
            this.iNameColor[i] = 0xffffff;
            iTongColor[i] = 0xffffff;
//            this.shPlayerOnePelsSpeedTime[i] = -1;
            //this.aniAvatarPet[i] = MainLogic.getInstance().aResManager.getAvatar(avatarId);
            bStartMoveToDest[i] = false;
            this.bStandNextTime[i] = false;
            lStopStartTime[i] = System.currentTimeMillis();
            iPetStopTime[i] = Tools.random(3000, 10000);
            this.byPetDirection[i] = this.byOtherDirection[i];
            this.iPetX[i] = this.iOtherXs[i] + iPetMaxOffset;
            this.iPetY[i] = this.iOtherYs[i];
            this.byPetStatus[i] = 0;
            this.byPetSpeed[i] = 2;
            this.iPetAniID[i] = -1;
            this.sPetNick[i] = null;
            this.shPetHeight[i] = 0;
            this.iPetDestX[i] = 0;
            this.iPetDestY[i] = 0;
        }
    }

    public byte getPlayerSex(int playerid) {
        switch ((playerid)) {
            case Constant.RES_PLAYER_MAN_ANI_PATH:
//            case Constant.RES_PLAYER_MAN_SWORD_ANI_PATH:
//            case Constant.RES_PLAYER_MAN_MASTER_ANI_PATH:
                return Constant.PLAYER_SEX_MAN;
//女角色动画文件
            case Constant.RES_PLAYER_WOMEN_ANI_PATH:
//            case Constant.RES_PLAYER_WOMEN_SWORD_ANI_PATH:
//            case Constant.RES_PLAYER_WOMEN_MASTER_ANI_PATH:
                return Constant.PLAYER_SEX_WOMAN;
        }
        return (byte) -1;
    }
}
